(* ============================================== *)
(* lexer pour l'analyse lexicale d'un fichier BPI *)
(* author Mathieu Barbin                          *)
(* version 1.0.*                                  *)
(* ============================================== *)

{ 
  open ParserBPI
  open Inputtools
}

rule lexem_list = parse
  | (['/'] ['*'] ([^'*'] | (['*'] [^'/']))* 
       ['*'] ['/']) as code                   { ignore (string_filtree (fun _ -> false) BPI_file code); 
						lexem_list lexbuf }     

  | (['/'] ['/'] [^'\n']* ['\n'])             { incr(index_ligne_bpi_file); 
						lexem_list lexbuf }
  | ['\n']                                    { incr(index_ligne_bpi_file); 
						lexem_list lexbuf }
  | [' ' '\t'] +                              { lexem_list lexbuf }
  | "#define"                                 { DEFINE }
  | "#setCPS"                                 { SETCPS }
  | "#where"                                  { DWHERE }
  | "where"                                   { WHERE }
  | "#end"                                    { DEND }
  | "#sysargv"                                { SYSARGV }
  | "#intargv"                                { SYSARGV }
  | "#stringargv"                             { STRINGARGV }
  | "#input"                                  { INPUT }
  | "#source"                                 { SOURCE }
  | "#init"                                   { INIT }
  | "text"                                    { TEXT }
  | "file"                                    { FILE }
  | "binaryfile"                              { BINARYFILE }
  | "argfun"                                  { ARGFUN }
  | "unitfun"                                 { UNITFUN }
  | "counter"                                 { COUNTER }
  | "log"                                     { LEX_LOG }
  | "mod"                                     { LEX_MOD }
  | "min"                                     { LEX_MIN }
  | "max"                                     { LEX_MAX }
  | "+"                                       { LEX_ADD }
  | "-"                                       { LEX_SUB }
  | "*"                                       { LEX_MULT }
  | "/"                                       { LEX_DIV }
  | "^"                                       { LEX_EXP }
  | "("                                       { LPAREN }
  | ")"                                       { RPAREN }
  | "="                                       { EGAL }
  | ".."                                      { POINTPOINT }
  | ","                                       { VIRG }
  | ";"                                       { POINT_VIRG }
  | ":"                                       { DEUX_POINTS }
  | "["                                       { LCROCHET }
  | "]"                                       { RCROCHET }
  | "{"                                       { LACC }
  | "}"                                       { RACC }
  | (['{'] [^'{']* ['}']) as code             { CODE01 (reduction01 BPI_file code) } 
  | (['0'-'9']+) as entier                    { INT (int_of_string entier) }
  | (['A'-'Z' 'a'-'z' '_' '\'' '~'] 
       ['A'-'Z' 'a'-'z' '0'-'9' '_' '\'' '~']*)
      as name                                 { IDENT name }
  | (['\"'] [^'\"']* ['\"']) as chaine        { STRING (reductionName BPI_file chaine) } 
  | (['%'] ['{'] ([^'}'] | (['}'] [^'%']))* ['}'] ['%']) as code             
      {   let filtre = (string_filtree (fun _ -> true) BPI_file code) in
	  let len = String.length filtre in
          CODE (String.sub filtre 2 (max 0 (len - 4))) }
  | eof                                       { EOF } 
